﻿using System;
using System.Device.Location;

namespace Utils.Gps
{
    public class Location
    {
        public event EventHandler Started;
        GeoCoordinateWatcher watcher;
        private GeoCoordinate location = null;
        
        public GeoCoordinate GetLocation()
        {
            if(watcher.Status== GeoPositionStatus.Ready)
                return watcher.Position.Location;
            return null;
        }
        public void Start()
        {
            watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
            
            watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged);

            watcher.Start();
        }

        void watcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
        {
            if (e.Status == GeoPositionStatus.Ready)
            {
                if (Started != null)
                {
                    Started(null, null);
                }
            }
        }

    }
}
